<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    

<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>  
<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>

</head>

	<script >
		//判断用户名是否重复
		function checkNameok(){
				var fl=true;
				$.ajax({
					  type:"post",
					  url:"AdminServlet.do?flog=nameok",
					  data:{adminName:$("#adminName").val()},
					  dataType:"text", 
					  async:false,
					  success:function(data){
						  alert(data);
						  if(data=="0"){
							  $("#adminName_msg").html("账号已被别人使用");
							  $("#adminName_msg").css("color","red");
							  fl=false;
						  }
						  else{
							  $("#adminName_msg").html("账号可用");
						  }	
					  }
				  });
				return fl;
		}
		
		//判断是否符合格式，adminName
		function checkName(){
			var reg=/^[a-zA-Z0-9]{4,15}$/;
			if(reg.test($("#adminName").val())){	
				return true;
			}
			$("#adminName_msg").html("4-15位；只限数字(0-9)和英文(a-z),不区分大小写").css("color","red");
			return false;
		}
		
		//password
		function checkPassword(){
			var reg=/^[a-zA-Z0-9]{6,20}$/;
			if(reg.test($("#password").val())){	
				return true;
			}
			$("#password_msg").html("数字或英文,6-20位").css("color","red");
			return false;
		}
		
		//pwdconfirm
		function checkPwdconfirm(){
			if($("#password").val()==$("#pwdconfirm").val()){
				return true;
			}else{
				$("#pwdconfirm_msg").html("与密码不同").css("color","red");
				return false;
			}
		}
		
		//清空
		function cleansp(){
			var sp=document.getElementsByTagName("label");
			for(var i=0;i<sp.length;i++){
				sp[i].innerHTML="";
			}
			
		}
	
		function tijiao(){
			cleansp();
			var result=true;
			
			if(checkNameok()==false){
				result=false;
			}
			
			if(checkName()==false){
				result=false;
			}
			
			if(checkPassword()==false){
				result=false;
			}
			
			if(checkPwdconfirm()==false){
				result=false;
			}
			
			if(result==true){
				return confirm("确定要提交吗");
			}else{
				alert("有错误");
				return result;
			}
			
		}
		
	</script>

<body>
     <div class ="div_title">
		 <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理员添加</span></div>
	 </div>
				 
	 <form action="AdminServlet.do?flog=admin_add" method="post" onsubmit="return tijiao()">
		 <table class="edit_table" >
		 		<tr>
		 			 	<td class="td_info">用户账号:</td>	
		 			 	<td class="td_input_short"> 
		 			 		<input type="text" class="txtbox" id="adminName" name="adminName" /> 
		 			 	</td>   
		 			 	<td>
		 			 		<label class="validate_info" id="adminName_msg"></label>
		 			 	</td> 
		 		</tr>
		 		<tr>
		 				<td class="td_info">用户密码:</td>	
		 				<td>
		 					<input type="password"  class="txtbox"  name="password"  id="password" />
		 				</td> 
		 				<td><label  class="validate_info" id="password_msg" ></label></td>	
		 		</tr>
		 		<tr>
		 				<td class="td_info">重复密码:</td>	
		 				<td><input type="password" class="txtbox" id="pwdconfirm"  /> 
		 				</td>
		 				<td><label  class="validate_info"  id="pwdconfirm_msg"></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info">备注信息:</td>	
		 			<td><textarea rows="4" cols="27" name="note" class="txtarea"></textarea> </td>	
		 			<td><label></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info"> </td>	
		 			<td> 
		 			<input class="form_btn" type="submit" value="提交" /> 
		 			<input type="reset"  class="form_btn" value="重置" onclick="return cleansp()" /> </td>	
		 			<td>
		 				<label id="result_msg" class="result_msg"></label>
		 			</td>	
		 		</tr>
		</table>
     </form>
     ${msg }
  </body>
</html>	
